﻿<%@ Page Title="QC SicoMill XRF" Language="C#" MasterPageFile="~/TableMaster.master" AutoEventWireup="true" CodeFile="qcsicomill_xrf.aspx.cs" Inherits="Pages_qcsicomill_xrf" enableEventValidation="true" %>

<%@ Register src="../UserControls/POTextBox.ascx" tagname="POTextBox" tagprefix="uc1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <style>
        @media only screen and (max-width: 760px), (min-device-width: 768px) and (max-device-width: 1024px) {

            .resTbl tr:nth-of-type(odd) {
                background-color: #CDE2FF;
            }

            .resTbl tr:nth-of-type(1) {
                display: none;
            }

            .resTbl td:nth-of-type(1):before {
                content: "Work Order #";
            }

            .resTbl td:nth-of-type(2):before {
                content: "Drum Number";
            }
            .resTbl td:nth-of-type(3):before {
                content: "Budgeted Qty";
            }
            .resTbl td:nth-of-type(4):before {
                content: "Actual Qty";
            }
            .resTbl td:nth-of-type(5):before {
                content: "Fe";
            }

            .resTbl td:nth-of-type(6):before {
                content: "Ca";
            }

            .resTbl td:nth-of-type(7):before {
                content: "Al";
            }

            .resTbl td:nth-of-type(8):before {
                content: "Remark";
            }

            .resTbl td:nth-of-type(9):before {
                content: "Is Active";
            }

            .resTbl td:nth-of-type(10):before {
                content: "Created By";
            }

            .resTbl td:nth-of-type(11):before {
                content: "Created Date";
            }
        }
    </style>
     <script type="text/javascript">
         var ddlRM_Order_Number, ddlDrum_Number;

         $(document).ready(function () {
             ddlRM_Order_Number = $("#<%=ddlWork_Order_Number.ClientID%>");
             ddlDrum_Number = $("#<%=ddlDRUM_Number.ClientID%>");           

             ddlRM_Order_Number.change(function () {
                getDrums();
            });
        });


         function save() {
             
             var Work_Order_Number = $('#MainContent_Add_ddlWork_Order_Number').val();
             var DRUM_Number = $('#MainContent_Add_ddlDRUM_Number').val();
             var Budgeted_Qty = $('#MainContent_Add_txtBudgeted_Qty').val();
             var Actual_Qty = $('#MainContent_Add_txtActual_Qty').val();
             var Fe = $('#MainContent_Add_txtFe').val();
             var Al = $('#MainContent_Add_txtAl').val();
             var Ca = $('#MainContent_Add_txtCa').val();           
             var Remark = $('#MainContent_Add_txtRemark').val();

             if (Work_Order_Number == "0") {
                 alert('Please Select Work Order Number');
                 return;
             }
             if (DRUM_Number == "0") {
                 alert('Please Select DRUM Number');
                 return;
             }

             //if (Budgeted_Qty == "") {
             //    alert('Please enter Budgeted Qty');
             //    return;
             //}
             if (Actual_Qty == "") {
                 alert('Please enter Actual Qty ');
                 return;
             }
             if (Fe == "") {
                 alert('Please enter Fe');
                 return;
             }
             if (Al == "") {
                 alert('Please enter Al');
                 return;
             }
             if (Ca == "") {
                 alert('Please enter Ca');
                 return;
             }
             if (Remark == "") {
                 alert('Please enter Remark');
                 return;
             }
             
             var inputs = ["MainContent_Add_ddlWork_Order_Number", "MainContent_Add_ddlDRUM_Number", "MainContent_Add_txtBudgeted_Qty", "MainContent_Add_txtActual_Qty", "MainContent_Add_txtFe", "MainContent_Add_txtAl", "MainContent_Add_txtCa", "MainContent_Add_txtRemark"];
             var fields = ["Work_Order_Number", "DRUM_Number", "Budgeted_Qty", "Actual_Qty", "Fe", "Al", "Ca", "Remark"];
             var editurl = (window.location.search).split('=');
             var Id = editurl[editurl.length - 1];
             if (Id == "") {
                 saveData('mytable', fields, inputs, 'Services.aspx/save_xrf');
             } else {
                 updateData('mytable', fields, inputs, 'Services.aspx/update_xrf', Id, "QC_XRF_ID");
             }
         }

         function getDrums() {
             if (window.location.search != "") {
                 ddlRM_Order_Number = $("#<%=ddlWork_Order_Number.ClientID%>");
                 
                 ddlDrum_Number = $("#<%=ddlDRUM_Number.ClientID%>");
             }

             ddlDrum_Number.empty();
             ddlDrum_Number.append("<option>Loading...</option>");

             $.ajax({
                 type: "POST",
                 url: "http://" + window.location.host + "/Inventory/Services/Services.aspx/getDrumNumberForxrf",
                 data: "{'WorkOrderNumber': '" + ddlRM_Order_Number.val() + "'}",
                 contentType: "application/json; charset=utf-8",
                 dataType: "json",
                 success: function (data) {

                     ddlDrum_Number.empty();

                     if (data.d.length == 0)
                         return;

                     ddlDrum_Number.append("<option value='0'>--Select DRUM--</option>");
                     $.each(data, function (i, item) {
                         $.each(item, function (j, ddlItem) {
                             ddlDrum_Number.append('<option  value="' + ddlItem.DRUM_BAG_Number + '"> ' + ddlItem.DRUM_BAG_Number + '</option>');
                         });
                         $('#MainContent_Add_ddlDRUM_Number').val($('#MainContent_Add_ddlDRUM_Number').attr('selectedval'));
                     });
                 }
             });
         }

         function updateDropDownValue() {

         }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="Add" runat="Server">


    <asp:Panel ID="pnlAdd" runat="server" CssClass="qcbg">

        <table id="mytable" cellpadding="0" cellspacing="0">

            <tr>
                <td style="width: 170px">
                    <asp:Label ID="lblWork_Order_Number" runat="server" AssociatedControlID="ddlWork_Order_Number" Text="Work Order #:"></asp:Label>
                </td>
                <td>
                    <asp:Label ID="lblDRUM_Number" runat="server" AssociatedControlID="ddlDRUM_Number" Text="Drum Number:"></asp:Label>
                </td>
                 <td>
                    <asp:Label ID="lblBudgeted_Qty" runat="server" AssociatedControlID="txtBudgeted_Qty" Text="Budgeted Qty:"></asp:Label>
                </td>
                 <td>
                    <asp:Label ID="lblActual_Qty" runat="server" AssociatedControlID="txtActual_Qty" Text="Actual Qty:"></asp:Label>
                </td>
                <td>
                    <asp:Label ID="lblFe" runat="server" AssociatedControlID="txtFe" Text="Fe:"></asp:Label>
                </td>
                <td>
                    <asp:Label ID="lblCa" runat="server" AssociatedControlID="txtCa" Text="Ca:"></asp:Label>
                </td>
                <td>
                    <asp:Label ID="lblAl" runat="server" AssociatedControlID="txtAl" Text="Al:"></asp:Label>
                </td>
                <td>
                    <asp:Label ID="lblRemark" runat="server" AssociatedControlID="txtRemark" Text="Remark:"></asp:Label>
                </td>
                <td></td>
            </tr>

            <tr>
                <td style="width: 170px">
                    <asp:DropDownList ID="ddlWork_Order_Number" runat="server" DataSourceID="DS_Work_Order_Num" DataTextField="Work_Order_Number" DataValueField="Work_Order_Number" OnDataBound="ddlWork_Order_Number_DataBound" AppendDataBoundItems="True">
                    </asp:DropDownList>
                    <asp:ObjectDataSource ID="DS_Work_Order_Num" runat="server" SelectMethod="selectAll" TypeName="DAL_tbl_sicomill_work_order"></asp:ObjectDataSource>
                </td>
                <td>
                    <%--<asp:TextBox ID="txtDRUM_Number" runat="server"></asp:TextBox>--%>
                    <asp:DropDownList ID="ddlDRUM_Number" runat="server" Width="103px"></asp:DropDownList>
                </td>
                <td>
                    <asp:TextBox ID="txtBudgeted_Qty" runat="server" Validate="Number"></asp:TextBox>
                </td>
                <td>
                    <asp:TextBox ID="txtActual_Qty" runat="server" Validate="Number"></asp:TextBox>
                </td>
                <td>
                    <asp:TextBox ID="txtFe" runat="server" Width="40px" Validate="Number"></asp:TextBox>
                </td>
                <td>
                    <asp:TextBox ID="txtCa" runat="server" Width="40px" Validate="Number"></asp:TextBox>
                </td>
                <td>
                    <asp:TextBox ID="txtAl" runat="server" Width="40px" Validate="Number"></asp:TextBox>
                </td>
                <td>
                    <asp:TextBox ID="txtRemark" runat="server"></asp:TextBox>
                </td>
                <td>
                    <button type="button" class="btn btn-default btn-xs" onclick="removeRow(this);"><span class="glyphicon glyphicon-remove"></span></button>
                </td>
            </tr>

            
        </table>
        <button type="button" class="btn btn-default btn-xs" onclick="addRow('mytable');"><span class="glyphicon glyphicon-plus"></span>Add Row</button>
        
        <br />
        
        <br />
        
        <input type="button" value="Save" style="width:90px" class="btn btn-success" onclick="save();" />
        <%-- <asp:Button ID="btnSave" runat="server" CssClass="btn btn-success" OnClick="btnSave_Click" Text="Save" Width="90px" />--%>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <asp:Button ID="btnCancel" runat="server" CssClass="btn btn-danger" OnClick="btnCancel_Click" Text="Cancel" Width="90px" />

        

        
    </asp:Panel>

</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="Grid" runat="Server">
    <asp:Panel ID="pnlList" runat="server">
        <asp:GridView ID="gridClients" runat="server" AutoGenerateColumns="False" CssClass="resTbl" DataSourceID="DS_tbl_qcsicomill_xrf">
            <Columns>
                <asp:BoundField DataField="Work_Order_Number" HeaderText="Work Order #" SortExpression="Work_Order_Number" />
                <asp:BoundField DataField="DRUM_Number" HeaderText="Drum Number" SortExpression="DRUM_Number" />
                <asp:BoundField DataField="Budgeted_Qty" HeaderText="Budgeted Qty" SortExpression="Budgeted_Qty" />
                <asp:BoundField DataField="Actual_Qty" HeaderText="Actual Qty" SortExpression="Actual_Qty" />
                <asp:BoundField DataField="Fe" HeaderText="Fe" SortExpression="Fe" />
                <asp:BoundField DataField="Ca" HeaderText="Ca" SortExpression="Ca" />
                <asp:BoundField DataField="Al" HeaderText="Al" SortExpression="Al" />
                <asp:BoundField DataField="Remark" HeaderText="Remark" SortExpression="Remark" />
                <asp:BoundField DataField="IS_ACTIVE" HeaderText="Is Active" SortExpression="IS_ACTIVE" />
                <asp:BoundField DataField="CREATED_BY" HeaderText="Created By" SortExpression="CREATED_BY" />
                <asp:BoundField DataField="CREATED_DATE" HeaderText="Created Date" SortExpression="CREATED_DATE" DataFormatString="{0:yyMMdd}"/>

                <asp:TemplateField HeaderText="Edit">
                    <ItemTemplate>
                        <asp:LinkButton ID="linkEdit" runat="server" Text="Edit" CommandArgument='<%# Eval("QC_XRF_ID") %>' OnClick="linkEdit_Click"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Delete">
                    <ItemTemplate>
                        <asp:LinkButton ID="linkDelete" CommandName="delete" runat="server" Text="Delete" OnClientClick="javascript:return confirm('Are you sure you want to delete this record?');" CommandArgument='<%# Eval("QC_XRF_ID") %>' OnClick="linkDelete_Click"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <asp:ObjectDataSource ID="DS_tbl_qcsicomill_xrf" runat="server" SelectMethod="selectAllForGrid" DeleteMethod="delete" InsertMethod="insert" UpdateMethod="update" TypeName="DAL_tbl_qcsicomill_xrf">
            <DeleteParameters>
                <asp:Parameter Name="QC_XRF_ID" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="Work_Order_Number" Type="String" />
                <asp:Parameter Name="DRUM_Number" Type="String" />
                <asp:Parameter Name="Budgeted_Qty" Type="Int32" />
                <asp:Parameter Name="Actual_Qty" Type="Int32" />
                <asp:Parameter Name="Fe" Type="Decimal" />
                <asp:Parameter Name="Al" Type="Decimal" />
                <asp:Parameter Name="Ca" Type="Decimal" />
                <asp:Parameter Name="Remark" Type="String" />
                <asp:Parameter Name="IS_ACTIVE" Type="Boolean" />
                <asp:Parameter Name="CREATED_BY" Type="String" />
                <asp:Parameter Name="CREATED_DATE" Type="DateTime" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="Work_Order_Number" Type="String" />
                <asp:Parameter Name="DRUM_Number" Type="String" />
                <asp:Parameter Name="Budgeted_Qty" Type="Int32" />
                <asp:Parameter Name="Actual_Qty" Type="Int32" />
                <asp:Parameter Name="Fe" Type="Decimal" />
                <asp:Parameter Name="Al" Type="Decimal" />
                <asp:Parameter Name="Ca" Type="Decimal" />
                <asp:Parameter Name="Remark" Type="String" />
                <asp:Parameter Name="IS_ACTIVE" Type="Boolean" />
                <asp:Parameter Name="UPDATED_BY" Type="String" />
                <asp:Parameter Name="UPDATED_DATE" Type="DateTime" />
            </UpdateParameters>
        </asp:ObjectDataSource>
    </asp:Panel>
</asp:Content>

